from PySide6.QtWidgets import QApplication, QPushButton, QSlider
from PySide6.QtCore import Qt



app = QApplication()

# =============== 1.普通按键 ===============
# 点击事件响应
def btn_clicked():
    print("普通按键点击")

btn = QPushButton('普通按键')

# signal 绑定 事件
btn.clicked.connect(btn_clicked) # 按下后马上松开，才会触发clicked事件
# btn.pressed.connect(btn_pressed)  # 按键按下
# btn.released.connect(btn_released)    # 按键放开
# btn.toggled.connect(btn_toggled)    # 按键切换选中（有参数checked）

# =============== 2.带solt（参数） 按键 ===============
# 点击事件响应
def btn_solt_clicked(data):
    print("solt按键点击, checked:", data)

btn_solt = QPushButton('带solt参数按键')
# !!! 激活按键的 solt 
btn_solt.setCheckable(True)

# signal 绑定 事件
btn_solt.clicked.connect(btn_solt_clicked)

# =============== 3. 滚动轴 Slider ===============
def slider_val_change(val):
    print('slider val:', val)

# slider = QSlider(Qt.Vertical) # 设置垂直方向的滚动轴
slider = QSlider(Qt.Horizontal) # 设置水平方向的滚动轴
# slider.setOrientation(Qt.Orientation.Horizontal)
#   设置slider的刻度未知：下方
slider.setTickPosition(QSlider.TickPosition.TicksBelow)
#   设置slider的刻度间隔
slider.setTickInterval(5)
slider.setRange(0, 100)
slider.setSingleStep(5)
# slider.setMinimum(0)
# slider.setMaximum(100)
slider.setValue(20)

slider.valueChanged.connect(slider_val_change)

btn.show()
btn_solt.show()
slider.show()
app.exec()